“Can I read this on my Kindle?”
“Can I read this on my Kindle?”
indiankanoon.org” is common for all links./doc/XXXX”, where “XXXX” is a specific number for that document.<tags>Find: Based on Location
tag.subTag.subsubTag
Find: Based on a tag’s id/attribute
find/find_all
#!/usr/bin/env python3
from bs4 import BeautifulSoup
import re
import subprocess
import sys
from urllib import request
urlBase = 'https://indiankanoon.org'
def generateMobi(urlId):
url = f'{urlBase}/doc/{urlId}'
try:
response = request.urlopen(url).read().decode('utf-8')
html = BeautifulSoup(response, 'lxml')
judgement = html.find('div', class_='judgments')
title = judgement.find('div', class_='doc_title').text
content = f'''
<html>
<head><title>{title}</title></head>
<body>{judgement}</body>
</html>
'''
content = re.sub(r'''(href=")([a-zA-Z0-9/]+)"''',
fr'''\1{urlBase}\2"''', content)
with open(f'{urlId}.html', 'w') as f:
f.write(content)
subprocess.run(f'''pandoc {urlId}.html --epub-cover-image="resources\supreme_court_india.jpg" -o {urlId}.epub''', shell=True)
subprocess.run(f'''kindlegen {urlId}.epub''', shell=True)
subprocess.run(f'''start {urlId}.epub''', shell=True)
except Exception as e:
print(e)
return None
if __name__ == '__main__':
generateMobi(sys.argv[1])#!/usr/bin/env python3
from bs4 import BeautifulSoup
import re
import subprocess
import sys
from urllib import request
urlBase = 'https://indiankanoon.org'
def generateMobi(urlId):
url = f'{urlBase}/doc/{urlId}'
try:
response = request.urlopen(url).read().decode('utf-8')
html = BeautifulSoup(response, 'lxml')
judgement = html.find('div', class_='judgments')
title = judgement.find('div', class_='doc_title').text
content = f'''
<html>
<head><title>{title}</title></head>
<body>{judgement}</body>
</html>
'''
content = re.sub(r'''(href=")([a-zA-Z0-9/]+)"''',
fr'''\1{urlBase}\2"''', content)
with open(f'{urlId}.html', 'w') as f:
f.write(content)
subprocess.run(f'''pandoc {urlId}.html --epub-cover-image="resources\supreme_court_india.jpg" -o {urlId}.epub''', shell=True)
subprocess.run(f'''kindlegen {urlId}.epub''', shell=True)
subprocess.run(f'''start {urlId}.epub''', shell=True)
except Exception as e:
print(e)
return None
if __name__ == '__main__':
generateMobi(sys.argv[1])#!/usr/bin/env python3
from bs4 import BeautifulSoup
import re
import subprocess
import sys
from urllib import request, error
urlBase = 'https://indiankanoon.org'
def generateMobi(urlId):
url = f'{urlBase}/doc/{urlId}'
try:
response = request.urlopen(url).read().decode('utf-8')
html = BeautifulSoup(response, 'lxml')
judgement = html.find('div', class_='judgments')
title = judgement.find('div', class_='doc_title').text
content = f'''
<html>
<head><title>{title}</title></head>
<body>{judgement}</body>
</html>
'''
content = re.sub(r'''(href=")([a-zA-Z0-9/]+)"''',
fr'''\1{urlBase}\2"''', content)
with open(f'{urlId}.html', 'w') as f:
f.write(content)
subprocess.run(f'''pandoc {urlId}.html --epub-cover-image="resources\supreme_court_india.jpg" -o {urlId}.epub''', shell=True)
subprocess.run(f'''kindlegen {urlId}.epub''', shell=True)
subprocess.run(f'''start {urlId}.epub''', shell=True)
except error.HTTPError as e:
print(e)
except error.URLError as e:
print(e)
except Exception as e:
print(e)
return None
if __name__ == '__main__':
generateMobi(sys.argv[1])